# -*- coding: utf-8 -*-
# @Time    : 2021/9/1 10:50
# @Author  : BrandonGT
# @FileName: 13_PyQt5_QBoxLayout.py

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *


class Window(QWidget):
    def __init__(self):
        super().__init__()  # 初始化继承的父类内部的__init__
        self.setWindowTitle("QBoxLayout的学习")
        self.resize(300, 300)
        self.setup_ui()

    def setup_ui(self):
        la1 = QLabel("标签1")
        la1.setStyleSheet("background-color: cyan;")
        la2 = QLabel("标签2")
        la2.setStyleSheet("background-color: yellow;")
        # la2.destroyed.connect(lambda : print("la2 删除"))
        la3 = QLabel("标签3")
        la3.setStyleSheet("background-color: red;")
        la4 = QLabel("标签4")
        la4.setStyleSheet("background-color: green;")
        la5 = QLabel("标签5")
        la5.setStyleSheet("background-color: blue;")
        la6 = QLabel("标签6")
        la6.setStyleSheet("background-color: pink;")

        # 1.创建布局管理器对象
        layout = QBoxLayout(QBoxLayout.TopToBottom)
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        # layout.setEnabled(False)

        v_layout = QBoxLayout(QBoxLayout.LeftToRight)
        v_layout.setSpacing(0)
        v_layout.setContentsMargins(0, 0, 0, 0)
        # v_layout.setEnabled(False)

        # 2.把布局管理器设置给需要的父对象
        self.setLayout(layout)

        # 3.把需要的子控件添加到父控件中
        layout.addWidget(la1, 1)
        layout.addWidget(la2, 1)
        # layout.addLayout(v_layout)
        layout.addWidget(la3, 3)

        v_layout.addWidget(la4)
        v_layout.addWidget(la5)
        v_layout.addWidget(la6)
        # layout.replaceWidget(la2, la4)
        # la2.deleteLater()
        # la2.hide()
        # la2.setParent(None)

        # 4.查询layout的各种数值
        # print(layout.contentsMargins().top())
        # print(layout.spacing())

        # timer = QTimer(self)
        # def change():
        #     layout.setDirection((layout.direction() + 1) % 4)
        #
        # timer.timeout.connect(change)
        # timer.start(50)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())